<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

use Framework\SlickGrid as SG;

class Welcome extends CI_Controller {

	function __construct()
	{
		parent::__construct();
	}

	function index()
	{
		$this->load->view('welcome_message');
	}
	
	function detail()
	{
		$this->load->library('doctrine');
		require_once SYSDIR.'/libraries/Doctrine/Common/ClassLoader.php';

		$classLoader = new Doctrine\Common\ClassLoader('Framework',  SYSDIR);
		$classLoader->register();
		
		$query = $this->doctrine->em->createQuery('SELECT a, u FROM models\Account a JOIN a.owners u WHERE a.active = 1 ORDER BY a.id');
		$query->setFirstResult(0);
		$query->setMaxResults(50);
		
		$columns = models\Account::getDefaultColumns();
		$columns->addColumn('login1', 'Login 1', array('getOwnerName', array(0)));
		$columns->addColumn('login2', 'Login 2', array('getOwnerName', array(1)));
		
		$grid = new SG\SlickGrid('user_accounts');
		$grid->setData(new SG\DoctrineGridDataProvider($query->getResult(), $columns));
		/*
		$output = new Framework\OutputGenerator();
		$output->addPageComponent($grid);
		$output->render();
		*/
		$output = new Framework\JSONOutputGenerator();
		$output->addWidget($grid);
		$output->render();
	}
}